package bat.iog.hytool.pattern.behavioral.observer.demo;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

public class Monitable {
    private List<Listener> listeners = new CopyOnWriteArrayList<>();

    public void addListener(Listener listener) {
        listeners.add(listener);
    }

    public void reomoveListener(Listener listener) {
        listeners.remove(listener);
    }

    public void init(){
        if (listeners.size() != 0) {
            for (Listener listener : listeners) {
                listener.init();
            }
        }
    }

    public void destroy(){
        if (listeners.size() != 0) {
            for (Listener listener : listeners) {
                listener.destory();
            }
        }
    }
}
